package com.istudy.dao.xyjdao.impl;
import java.util.Date;

import com.istudy.dao.xyjdao.BaseDao;
import com.istudy.dao.xyjdao.VideoIntDao;
import com.istudy.entity.Video;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author xdd
 * @create 2020-08-24 16:30
 */
public class VideoImplDao extends BaseDao implements VideoIntDao {

    /**
     * 父类所需要的数据库连接对象
     * @param conn
     */
    public VideoImplDao(Connection conn) {
        super(conn);
    }

    /**
     * 根据视频类型id获取播放列表
     *
     * @return 视频播放列表
     */
    @Override
    public List<Video> selectVideoAll(int videpType) throws SQLException {
        List<Video> videoList=new ArrayList<>();//视频列表
        String sql="SELECT * \n" +
                "FROM `video`\n" +
                "WHERE `video_type`=?;";
        ResultSet resultSet = super.executeQuery(sql, videpType);
        while (resultSet.next()){
            Video video = mapperObject(resultSet);
            videoList.add(video);
        }
        return videoList;
    }



    /**
     * 根据查询结果集（ResultSet），映射数据库对象
     *
     * @param rs
     * @return 映射对象
     */
    @Override
    public Video mapperObject(ResultSet rs) throws SQLException {
        Video video=new Video();
        video.setVideoId(rs.getInt("video_id"));
        video.setVideoName(rs.getString("video_name"));
        video.setVideoAddress(rs.getString("video_address"));
        video.setVideoConsume(rs.getInt("video_consume"));
        video.setVideoType(rs.getString("video_type"));
        video.setVideoPicture(rs.getString("video_picture"));
        video.setVideoDescrtion(rs.getString("video_descrtion"));
        video.setVideoUploadUser(rs.getString("video_upload_user"));
        video.setVideoUploadTime(rs.getString("video_upload_time"));
        return video;
    }


}
